<?php // echo '<pre>'; print_r($this->data); exit;                    ?>
<script type="text/javascript" src="/siscel/js/paciente.js"></script>
<link rel="stylesheet" type="text/css" href="/siscel/css/upload.css" />
<div id="msg"></div>
<?php $codigo_pais = isset($this->data['Paciente']['CD_PAIS']) ? $this->data['Paciente']['CD_PAIS'] : NULL ?>
<?php $codigo_cidade = isset($this->data['Paciente']['CD_UF']) ? $this->data['Paciente']['CD_UF'] : NULL ?>
<?php $codigo_cidade = isset($this->data['Paciente']['CD_CID_NAT']) ? $this->data['Paciente']['CD_CID_NAT'] : NULL ?>
<form name="formularioCadastroPaciente" id="formularioCadastroPaciente" method="POST">
    <?php echo $this->Form->input('Paciente.CD_PAC', array('type' => 'hidden', 'id' => 'CD_PAC', 'value' => $CD_PAC)); ?>
    <?php echo $this->Form->input('codigo_pais', array('type' => 'hidden', 'id' => 'codigo_pais', 'value' => $codigo_pais)); ?>
    <?php echo $this->Form->input('codigo_uf', array('type' => 'hidden', 'id' => 'codigo_uf', 'value' => $codigo_pais)); ?>
    <?php echo $this->Form->input('codigo_cidade', array('type' => 'hidden', 'id' => 'codigo_cidade', 'value' => $codigo_cidade)); ?>
    <fieldset>
        <div id="divCadastroBasico"> 
            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                <th colspan="3">
                    <b>INFORMAÇÕES BÁSICAS</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_lapis.gif" id="alterarCadastro" />
                </th>
                </thead>
                <tr>
                    <td colspan="2">
                        <?php echo $this->Form->input('Paciente.NM_PAC', array('type' => 'text', 'label' => 'Nome', 'id' => 'NM_PAC', 'class' => 'campoAlfa formee-req', 'size' => "30", 'maxlength' => "120")); ?>
                    </td>
                    <td width="25%">
                        <?php echo $this->Form->input('Paciente.NUM_CPF_PAC', array('type' => 'text', 'label' => 'CPF', 'id' => 'NUM_CPF_PAC', 'class' => 'campoCPF required', 'size' => "20", 'maxlength' => "14", 'readonly' => $bloquear)); ?>
                    </td>
                    <td width="25%">
                        <?php echo $this->Form->input('Paciente.SEXO', array('type' => 'select', 'label' => 'Sexo', 'id' => 'SEXO', 'options' => array('' => 'Selecione um item', 'M' => 'Masculino', 'F' => 'Feminino', 'N' => 'Não Informado',))); ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <?php echo $this->Form->input('Paciente.NM_MAE', array('type' => 'text', 'label' => 'Nome da Mãe', 'id' => 'NM_MAE', 'class' => 'campoAlfa', 'size' => "30", 'maxlength' => "120")); ?>
                    </td>
                    <td>
                        <?php echo $this->Form->input('Paciente.RACA', array('type' => 'select', 'label' => 'Raça', 'id' => 'RACA', 'options' => $arrRaca)); ?>
                    </td>
                    <td>
                        <?php echo $this->Form->input('Paciente.CO_ETNIA', array('type' => 'select', 'label' => 'Etnia', 'id' => 'CO_ETNIA', 'options' => $arrEtnia)); ?>
                    </td>            
                </tr>
                <tr>
                    <td>
                        <?php echo $this->Form->input('Paciente.DT_NASC', array('type' => 'text', 'label' => 'Nascimento', 'id' => 'DT_NASC', 'class' => 'campoData', 'maxlength' => "14", 'readonly' => $bloquear)); ?>
                    </td>
                    <td>
                        <?php echo $this->Form->input('Paciente.PAIS', array('type' => 'select', 'label' => 'País', 'id' => 'PAIS', 'options' => $arrPais)); ?>
                    </td>      
                    <td>
                        <?php echo $this->Form->input('Paciente.CD_UF', array('type' => 'select', 'label' => 'UF', 'id' => 'CD_UF', 'options' => $arrUf /* 'options' => array('' => 'Selecione um item' ) */)); ?>
                    </td>   
                    <td>
                        <?php echo $this->Form->input('Paciente.CD_CID_NAT', array('type' => 'select', 'label' => 'Cidade Nascimento', 'id' => 'CD_CID_NAT', 'options' => $arrCidade)); ?>
                    </td>   
                </tr>
                <tr>
                    <td colspan="2">
                        <?php echo $this->Form->input('Paciente.EMAIL', array('type' => 'email', 'label' => 'Email principal', 'id' => 'EMAIL', 'class' => 'campoEmail', 'size' => "30", 'maxlength' => "60")); ?>
                    </td>
                    <td colspan="2">
                        <?php echo $this->Form->input('Paciente.E_MAIL', array('type' => 'email', 'label' => 'Email secundario', 'id' => 'E_MAIL', 'class' => 'campoEmail', 'size' => "30", 'maxlength' => "60")); ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <?php echo $this->element('telefone/cadastroFone'); ?>
                    </td>
                    <td style="text-align: right;">
                        <div >
                            <?php
                            $usuarioRequest = $this->request->data('Usuario');
                            if (!empty($usuarioRequest['IM_FOTO'])) :
                                echo $this->Siscel->foto($usuarioRequest['IM_FOTO']);
                            else:
                                echo $this->Html->image('/img/perfil.jpg', array('width' => '100', 'heigth' => '133', 'label' => null));
                            endif;
                            ?>
                        </div>
                        <?php if (!$CD_PAC): ?>
                        <div style="float:right">
                            <!-- a href="#upload" class="input upload ">
                                <button type="button">Incluir / Alterar Foto</button -->
                                <?php echo $this->Form->input('InstituicaoLab.fotoUsuario', array('type' => 'file', 'size' => '0', 'style' => 'width: 100px;', 'label' => '', 'class' => '')); ?>
                            <!-- /a -->
                        </div>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;" colspan="4">
                        <?php if (!$CD_PAC) echo '<div class="submit"><input type="submit" value="Enviar"></div>'; ?>
                    </td>
                </tr>
            </table>
        </div>
        <?php if ($CD_PAC) : ?>
        <div id="divCadastroComplementar">
            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                <th colspan="3">
                    <b>INFORMAÇÕES HIV</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_lapis.gif" id="addHiv" title="Adicionar Informações HIV"/>
                </th>
                </thead>
                <tbody>
                    <tr>
                        <td colspan="2">Data Dignóstico</td>
                        <td>Data Antiretroviral</td>
                        <td style="text-align: center;">Caso AIDS</td>
                    </tr>
                    <tr id="listSemHiv">
                        <?php if ($this->data['Paciente']['CASO_AIDS']): ?>
                            <td colspan="2"><?php if ($this->data['Paciente']['NU_MES_DIAG_HIV']) echo $this->data['Paciente']['NU_MES_DIAG_HIV'] . '/' . $this->data['Paciente']['NU_ANO_DIAG_HIV'] ?></td>
                            <td><?php if ($this->data['Paciente']['DT_INIC_ANTI_RETRO']) echo date('d/m/Y', strtotime($this->data['Paciente']['DT_INIC_ANTI_RETRO'])) ?></td>
                            <td style="text-align: center;"><?php echo ($this->data['Paciente']['CASO_AIDS'] == 'S') ? 'SIM' : 'NÃO' ?></td>
                        <?php else : ?>
                            <td colspan="3">Sem registros</td>
                            <td></td>
                        <?php endif; ?>
                    </tr>
                <tbody>
            </table>

            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                <th colspan="3">
                    <b>INFORMAÇÕES COMPLEMENTARES</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_lapis.gif" id="addComplementar" />
                </th>
                </thead>
                <tbody>
                    <tr>
                            <?php if ($this->data['Paciente']['NM_PAI']) : ?>
                        <td colspan="3">Filiação / Documentos</td>
                        <td>Endereço</td>
                            <?php else: ?>
                        <td colspan="3">Sem registros</td>
                        <td></td>
                            <?php endif; ?>
                    </tr>
                <tbody>
            </table>

            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                <th colspan="3">
                    <b>RESPONSÁVEL</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_lapis.gif" id="addResponsavel" />
                </th>
                </thead>
                <tbody>
                        <?php if (count($this->data['RESPONSAVEL'])) : ?>
                            <?php $i = 0; ?>
                            <?php foreach ($this->data['RESPONSAVEL'] as $responsavel) : ?>
                                <tr>
                                    <td colspan="2">Nome: <?php echo $responsavel[$i]['NO_RESPONSAVEL'] ?></td>
                                    <td>CPF: <?php echo $responsavel[$i]['NU_CPF_RESPONSAVEL'] ?></td>
                                    <td><img alt="Excluir Responsavel" title="Excluir " src="/siscel/img/excluir.gif" onclick="Paciente.excluirResponsavel('<?php echo $responsavel[$i]['CO_RESPONSAVEL'] ?>')"></td>
                                </tr>
                                <?php
                                $i++;
                            endforeach;
                            ?>

                        <?php else : ?>
                    <tr>
                        <td colspan="3">Sem registros</td>
                        <td></td>
                    </tr>
                        <?php endif; ?>
                <tbody>
            </table>

            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                <th colspan="3">
                    <b>SITUAÇÃO</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_lapis.gif" id="cadastrarSituacao" />
                </th>
                </thead>
                <tbody>
                        <?php $i = 0; ?>
                        <?php if (count($this->data['SITUACAO'])) : ?>
                            <?php foreach ($this->data['SITUACAO'] as $situacao) : ?>
                    <tr>
                        <td colspan="2"><?php echo $situacao[$i]['DS_SITUACAO_PACIENTE'] ?></td>
                        <td colspan="2"><?php echo $situacao[$i]['DS_MOTIVO'] ?></td>
                    </tr>
                            <?php endforeach; ?>
                        <?php else : ?>
                    <tr>
                        <td colspan="3">Sem registros</td>
                        <td></td>
                    </tr>
                        <?php endif; ?>
                </tbody>
            </table>

            <table width="98%" border="0" cellspacing="0" cellpadding="0" style="border: none !important;">
                <tr>
                    <td>
                        <?php //if (!$CD_PAC) echo '<div class="submit"><input type="submit" value="Enviar"></div>'; ?>
                        <?php if ($CD_PAC) echo '<div class="submit"><input type="button" value="Fechar" onclick="Paciente.fecharAlteracao();"></div>'; ?>
                    </td>
                </tr>
            </table>
        </div>
        <?php endif; ?>
    </fieldset>
</form>

<div id="dlgHIV" title="Informações HIV" style="display: none;">
    <div>
        <table>
            <tr>
                <td>
                    <?php echo $this->Form->input('dtaDiagnostico', array('type' => 'text', 'label' => 'Diagnóstico HIV', 'id' => 'dtaDiagnostico', 'class' => 'campoData', 'maxlength' => "14")); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $this->Form->input('dtaAntiretroviral', array('type' => 'text', 'label' => '1.o Antiretroviral', 'id' => 'dtaAntiretroviral', 'class' => 'campoData', 'maxlength' => "14")); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php
                    $options = array('S' => 'Sim', 'N' => 'Não');
                    $attributes = array('legend' => false);
                    echo $this->Form->radio('dtaCaso', $options, $attributes);
                    ?>
                </td>
            </tr>
        </table>
    </div>
</div>
<?php echo $this->element('pacientes/informacao-complementar'); ?>

<div id="dlgRepresentante" title="Adicionar Responsável" style="display: none;">
    <div>
        <table>
            <tr>
                <td>
                    <?php echo $this->Form->input('nomeResponsavel', array('type' => 'text', 'label' => 'Responsável', 'id' => 'nomeResponsavel', 'maxlength' => "60", 'minlength' => '2')); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $this->Form->input('cpfResponsavel', array('type' => 'text', 'label' => 'CPF', 'id' => 'cpfResponsavel', 'maxlength' => "14", 'class' => 'campoCPF')); ?>
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="dialogSituacao" title="Adicionar Situação" style="display: none;">
    <div>
        <table>
            <tr>
                <td>
                    <?php echo $this->Form->input('CO_SITUACAO', array('type' => 'select', 'label' => 'Situação', 'id' => 'CO_SITUACAO', 'maxlength' => "150", 'options' => $arrSituacao)); ?>
                </td>
                <td>
                    <?php echo $this->Form->input('CO_MOTIVO', array('type' => 'select', 'label' => 'Situação', 'id' => 'CO_MOTIVO', 'maxlength' => "150", 'options' => $arrMotivo)); ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?php echo $this->Form->input('DS_SITUACAO', array('type' => 'textarea', 'label' => 'Observações', 'id' => 'DS_SITUACAO', 'maxlength' => "150", 'class' => 'required')); ?>
                </td>
            </tr>
        </table>        
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        Paciente.init();
    });
</script>